package com.keqing.controller;

import com.ganyu.domain.ResponseResult;
import com.ganyu.domain.dto.AdminUserRoleDto;
import com.ganyu.domain.vo.AdminInsertUserVo;
import com.ganyu.service.impl.AdminUserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * DATA: 2022/10/2
 * Author: 晨夕
 */

@RestController
@RequestMapping("/system/user")
public class AdminUserController {

    @Autowired
    private AdminUserServiceImpl adminUserServiceImpl;


    @GetMapping("/list")
    public ResponseResult selectUserList(Integer pageNum,Integer pageSize,String userName,String phonenumber,String status){
        return adminUserServiceImpl.selectUserList(pageNum, pageSize, userName, phonenumber,status);
    }
    @PreAuthorize("@ps.hasPermission()")
    @PostMapping
    public ResponseResult insertUser(@RequestBody AdminUserRoleDto adminUserRoleDto){
        return adminUserServiceImpl.insertUser(adminUserRoleDto);
    }
    @PreAuthorize("@ps.hasPermission()")
    @DeleteMapping("/{id}")
    public ResponseResult deleteUser(@PathVariable("id") Long[] ids){
        return adminUserServiceImpl.deleteUser(ids);
    }

    @GetMapping("/{id}")
    public ResponseResult selectUser(@PathVariable Long id){
        return adminUserServiceImpl.selectUser(id);
    }
    @PreAuthorize("@ps.hasPermission()")
    @PutMapping
    public ResponseResult updateUser(@RequestBody AdminInsertUserVo adminInsertUserVo){
        return adminUserServiceImpl.updateUser(adminInsertUserVo);
    }
}
